let obj = {
    name: 123
}
function test() {
    console.log(123, this)
}
//test.call(obj)
Function.prototype.myCall = function (thisObj, ...args) {
    let Func = this
    let sym = Symbol("myFunc")
    thisObj[sym] = Func
    thisObj[sym](args)
    delete thisObj[sym]
}
test.myCall(obj, 7, 8, 9)
// let obj1 = {
//     name:"张三"
// }
// function getName(){
//      console.log('123',this)
// }
// Function.prototype.myCall = function(obj,...args){
//     let Fun =  this
//     obj["myFunction"] = Fun
//     obj["myFunction"](args)
// }
// getName.myCall(obj1,1,2,3)

//bind
this.name = "jack";
let demo = {
    name: "rose",
    getName: function () { return this.name; }
}
console.log(demo.getName());//输出rose  这里的this指向demo

let another=demo.getName;
console.log(another())//输出jack  这里的this指向全局对象
//运用bind方法更改this指向
let another2=another.bind(demo);
console.log(another2());//输出rose  这里this指向了demo对象了
Function.prototype.MyBind = function (target) {
    let Fun = this
    return function(){
        return Fun.apply(target || window.args);
    }
}
let a = another.MyBind(demo)